package com.chhuang.application;

import java.io.InputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 启动服务
 * @author CHHUANG
 *
 */
public class App {
	private static final Log log = LogFactory.getLog(App.class);
	
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		//修改log4j文件路径，默认是在包根目录下，就是java或者resource文件夹下。
		InputStream in = App.class.getResourceAsStream("/config/log4j.properties");
		PropertyConfigurator.configure(in);
		
		//加载spring
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:config/spring/applicationContext.xml");
		context.start();
		
		// 保证服务一直开着
		
		/*方法1.使用System.in.read阻塞，在后台运行jar时就不起作用了，因为没有控制台
		 * 比如在linux服务器上用带&命令起动表示后台运行：
		 * nohup java -jar *.jar &
		try {
			log.info("Application server is running...");
			System.in.read();
		} catch (IOException e) {
			e.printStackTrace();
		}
		*/
		
		//方法2.Thread.sleep
		while(true){
			try {
				log.info("Application server is running...");
				Thread.sleep(24*60*60*1000l);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
}
